/*
 * JerboArticles.java
 *
 * Created on March 7, 2008, 11:23 AM
 */

package jerbo;

import jerbo.util.event.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import jerbo.util.ResultSetTableModel;
import jerbo.util.TableSorter;
import org.jdesktop.application.Application;
import org.jdesktop.application.Action;

/**
 *
 * @author  Luigi Paioro
 */
public class JerboArticles extends javax.swing.JInternalFrame {
    
    private java.util.ResourceBundle bundle = 
            java.util.ResourceBundle.getBundle("jerbo/resources/JerboArticles");
        
    private String filter = filter = "select articles.*, sum(stock.quantity) as quantity from articles left join stock on articles.description = stock.article group by description ";
    
    private ArticleEventSource articleSourceEvent = new ArticleEventSource();
    
    
    /** Creates new form JerboArticles */
    @SuppressWarnings("empty-statement")
    public JerboArticles() {
        
        initComponents();
        refreshTable();        
        
    }
    
    public ArticleEventSource asArticleEventSource() {
        return articleSourceEvent;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        topPanel = new javax.swing.JPanel();
        filterPanel = new javax.swing.JPanel();
        supplierLabel = new javax.swing.JLabel();
        supplierTextField = new javax.swing.JTextField();
        descriptionLabel = new javax.swing.JLabel();
        descriptionTextField = new javax.swing.JTextField();
        filterButton = new javax.swing.JButton();
        categoryLabel = new javax.swing.JLabel();
        categoryTextField = new javax.swing.JTextField();
        articlesScrollPane = new javax.swing.JScrollPane();
        articlesTable = new javax.swing.JTable();

        bottomPanel = new javax.swing.JPanel();
        closeButton = new javax.swing.JButton();
        modifyButton = new javax.swing.JButton();
        addButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("jerbo/resources/JerboArticles"); // NOI18N
        setTitle(bundle.getString("title")); // NOI18N
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/jerbo/resources/leaf.png"))); // NOI18N
        setName("articlesManager"); // NOI18N

        topPanel.setName("topPanel"); // NOI18N

        filterPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("filterPanel.border.title"))); // NOI18N
        filterPanel.setName("filterPanel"); // NOI18N

        supplierLabel.setText(bundle.getString("supplierLabel.text")); // NOI18N
        supplierLabel.setName("supplierLabel"); // NOI18N

        supplierTextField.setName("supplierTextField"); // NOI18N
        supplierTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                keyEnterPressedToFilter(evt);
            }
        });

        descriptionLabel.setText(bundle.getString("descriptionLabel.text")); // NOI18N
        descriptionLabel.setName("descriptionLabel"); // NOI18N

        descriptionTextField.setName("descriptionTextField"); // NOI18N
        descriptionTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                keyEnterPressedToFilter(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(jerbo.JerboApp.class).getContext().getActionMap(JerboArticles.class, this);
        filterButton.setAction(actionMap.get("setFilter")); // NOI18N
        filterButton.setText(bundle.getString("filterButton.text")); // NOI18N
        filterButton.setName("filterButton"); // NOI18N

        categoryLabel.setText(bundle.getString("categoryLabel.text")); // NOI18N
        categoryLabel.setName("categoryLabel"); // NOI18N

        categoryTextField.setName("categoryTextField"); // NOI18N
        categoryTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                keyEnterPressedToFilter(evt);
            }
        });

        org.jdesktop.layout.GroupLayout filterPanelLayout = new org.jdesktop.layout.GroupLayout(filterPanel);
        filterPanel.setLayout(filterPanelLayout);
        filterPanelLayout.setHorizontalGroup(
            filterPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(filterPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(filterPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(supplierTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 179, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(supplierLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(filterPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(descriptionTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 203, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(descriptionLabel))
                .add(12, 12, 12)
                .add(filterPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(filterPanelLayout.createSequentialGroup()
                        .add(categoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 203, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(filterButton))
                    .add(categoryLabel))
                .addContainerGap(93, Short.MAX_VALUE))
        );
        filterPanelLayout.setVerticalGroup(
            filterPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(filterPanelLayout.createSequentialGroup()
                .add(filterPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(descriptionLabel)
                    .add(supplierLabel)
                    .add(categoryLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(filterPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(supplierTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(descriptionTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(categoryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(filterButton))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout topPanelLayout = new org.jdesktop.layout.GroupLayout(topPanel);
        topPanel.setLayout(topPanelLayout);
        topPanelLayout.setHorizontalGroup(
            topPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(topPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(filterPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        topPanelLayout.setVerticalGroup(
            topPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(topPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(filterPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        articlesScrollPane.setName("articlesScrollPane"); // NOI18N

        articlesTable.setModel(getTableModel());
        articlesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        articlesTable.setName("articlesTable"); // NOI18N
        articlesTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                selectArticle(evt);
            }
        });
        articlesScrollPane.setViewportView(articlesTable);

        bottomPanel.setName("bottomPanel"); // NOI18N

        closeButton.setAction(actionMap.get("close")); // NOI18N
        closeButton.setText(bundle.getString("closeButton.text")); // NOI18N
        closeButton.setName("closeButton"); // NOI18N

        modifyButton.setAction(actionMap.get("modifyArticle")); // NOI18N
        modifyButton.setText(bundle.getString("modifyButton.text")); // NOI18N
        modifyButton.setName("modifyButton"); // NOI18N

        addButton.setAction(actionMap.get("addArticle")); // NOI18N
        addButton.setText(bundle.getString("addButton.text")); // NOI18N
        addButton.setName("addButton"); // NOI18N

        jButton1.setAction(actionMap.get("deleteArticle")); // NOI18N
        jButton1.setText(bundle.getString("deleteButton.text")); // NOI18N
        jButton1.setName("deleteButton"); // NOI18N

        org.jdesktop.layout.GroupLayout bottomPanelLayout = new org.jdesktop.layout.GroupLayout(bottomPanel);
        bottomPanel.setLayout(bottomPanelLayout);
        bottomPanelLayout.setHorizontalGroup(
            bottomPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, bottomPanelLayout.createSequentialGroup()
                .addContainerGap(402, Short.MAX_VALUE)
                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(addButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(modifyButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(closeButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        bottomPanelLayout.setVerticalGroup(
            bottomPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(bottomPanelLayout.createSequentialGroup()
                .add(bottomPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(closeButton)
                    .add(modifyButton)
                    .add(addButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(bottomPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(topPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(articlesScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 808, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(topPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(articlesScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(bottomPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void keyEnterPressedToFilter(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyEnterPressedToFilter
        
        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER)
            this.setFilter();
        
    }//GEN-LAST:event_keyEnterPressedToFilter

    private void selectArticle(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_selectArticle
        
        if (evt.getClickCount() == 2) {
            javax.swing.JTable target = (javax.swing.JTable) evt.getSource();
            int row = target.getSelectedRow();
            // do some action
            //String code = target.getValueAt(row, 0).toString();
            //articleSourceEvent.notifySelection(code);
            String desc = target.getValueAt(row, 1).toString();
            articleSourceEvent.notifySelection(desc);
         }
        
    }//GEN-LAST:event_selectArticle
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JScrollPane articlesScrollPane;
    private javax.swing.JTable articlesTable;
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JLabel categoryLabel;
    private javax.swing.JTextField categoryTextField;
    private javax.swing.JButton closeButton;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JTextField descriptionTextField;
    private javax.swing.JButton filterButton;
    private javax.swing.JPanel filterPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton modifyButton;
    private javax.swing.JLabel supplierLabel;
    private javax.swing.JTextField supplierTextField;
    private javax.swing.JPanel topPanel;
    // End of variables declaration//GEN-END:variables
    

    private String getFilter() {
        return filter;
    }
    
    @Action
    public void setFilter()  {
        filter = "select articles.*, sum(stock.quantity) as quantity from articles left join stock on articles.description = stock.article ";
        String where = "";
        String supplier = supplierTextField.getText().toUpperCase().trim();
        String description = descriptionTextField.getText().toUpperCase().trim();
        String category = categoryTextField.getText().toUpperCase().trim();
        if (!supplier.equals(""))
            where += " AND supplier LIKE '%"+supplier.replaceAll("'", "''")+"%'";
        if (!description.equals(""))
            where += " AND description LIKE '%"+description.replaceAll("'", "''")+"%'";
        if (!category.equals(""))
            where += " AND category LIKE '%"+category.replaceAll("'", "''")+"%'";
        if (where.startsWith(" AND "))
            where = where.substring(5);
        if (!where.equals(""))
            where = " where " + where;
        filter += where + " group by description";
        this.refreshTable();
     }
    
    protected TableModel getTableModel() {
        try {
            Connection conn = Application.getInstance(jerbo.JerboApp.class).getConnection();
            Statement stat = conn.createStatement();
            ResultSet result = stat.executeQuery(getFilter());
            TableSorter sorter = new TableSorter((TableModel) 
                    new ResultSetTableModel(Application.getInstance(jerbo.JerboApp.class)
                    .cacheResultSet(result), bundle));
            sorter.setTableHeader(articlesTable.getTableHeader());
            if (result != null) result.close();
            if (stat != null) stat.close();
            return sorter;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    /**
     * 
     */
    @Action
    public void close() {
        this.setVisible(false);
    }
    
    @Action
    public void deleteArticle() {
        
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jerbo.JerboApp.class).getContext().getResourceMap(JerboAboutBox.class);
        try {
//            String code = articlesTable.getValueAt(articlesTable.getSelectedRow(), 0).toString();
            String desc = articlesTable.getValueAt(articlesTable.getSelectedRow(), 1).toString();
//            if (code.equals("")) {
            if (desc.equals("")) {
                javax.swing.JOptionPane.showMessageDialog(JerboApp.getApplication().getMainFrame(),
                        bundle.getString("msg.noArticleSelected"));
            } else {
//                int opt = javax.swing.JOptionPane.showConfirmDialog(JerboApp.getApplication().getMainFrame(),
//                        bundle.getString("msg.deleteAlert") + " "+ code + "?",
//                        resourceMap.getString("Application.title"),
//                        javax.swing.JOptionPane.OK_CANCEL_OPTION);
                int opt = javax.swing.JOptionPane.showConfirmDialog(JerboApp.getApplication().getMainFrame(),
                        bundle.getString("msg.deleteAlert") + " "+ desc + "?",
                        resourceMap.getString("Application.title"),
                        javax.swing.JOptionPane.OK_CANCEL_OPTION);
                if (opt == javax.swing.JOptionPane.YES_OPTION) {
                    try {
                        Connection conn = Application.getInstance(jerbo.JerboApp.class).getConnection();
                        Statement stat = conn.createStatement();
//                        stat.executeUpdate("delete from articles where code='" + code + "'");
                        stat.executeUpdate("delete from articles where description=\"" + desc + "\"");
                        if (stat != null) stat.close();
                        this.refreshTable();
                    } catch (SQLException ex) {
                        Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        } catch (Exception e) {
            javax.swing.JOptionPane.showMessageDialog(JerboApp.getApplication().getMainFrame(), bundle.getString("msg.noArticleSelected"));
        }
    }
    
    /**
     * 
     */
    @Action
    @SuppressWarnings("empty-statement")
    public void modifyArticle() {
        if (manageBox == null) {
            JFrame mainFrame = JerboApp.getApplication().getMainFrame();
            manageBox = new JerboArticlesManage(mainFrame);
            manageBox.setLocationRelativeTo(mainFrame);
        }
        manageBox.setMode(JerboArticlesManage.TYPE_MODIFY);
//        manageBox.loadArticle(articlesTable.getValueAt(articlesTable.getSelectedRow(), 0).toString());
        manageBox.loadArticle(articlesTable.getValueAt(articlesTable.getSelectedRow(), 1).toString());
        JerboApp.getApplication().show(manageBox);
        this.refreshTable();
    }
    
    /**
     * 
     */
    @Action
    public void addArticle() {
        if (manageBox == null) {
            JFrame mainFrame = JerboApp.getApplication().getMainFrame();
            manageBox = new JerboArticlesManage(mainFrame);
            manageBox.setLocationRelativeTo(mainFrame);
        }
        manageBox.setMode(JerboArticlesManage.TYPE_ADD);
        JerboApp.getApplication().show(manageBox);
        this.refreshTable();
    }
    
    /**
     * 
     */
    @SuppressWarnings("empty-statement")
    public void refreshTable() {
        
        articlesTable.setModel(this.getTableModel());
        
        class TableChangeColumnSizeListener implements TableColumnModelListener {

            private Properties customProperties = new Properties();
            private String customPropertiesFilePath = jerbo.JerboApp.class.getResource(
                        "/jerbo/resources/JerboArticlesCustom.properties")
                        .toString().substring(5);
                         
            public void columnMarginChanged(ChangeEvent e) {
                try {
                    customProperties.load(new FileInputStream(customPropertiesFilePath));
                    TableColumnModel tbm = (TableColumnModel) e.getSource();
                    for (int i = 0; i < tbm.getColumnCount(); i++)
                        customProperties.setProperty("table.columns[" + i + "].width",
                                String.valueOf(tbm.getColumn(i).getWidth()));
                    customProperties.store(new FileOutputStream(customPropertiesFilePath), null);
                } catch (IOException ex) {
                    Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            public void columnAdded(TableColumnModelEvent e) {}
            public void columnRemoved(TableColumnModelEvent e) {}
            public void columnMoved(TableColumnModelEvent e) {}
            public void columnSelectionChanged(ListSelectionEvent e) {}

        };
        
        class JTableSelectSortListener implements TableModelListener {
            
            private Properties customProperties = new Properties();
            private String customPropertiesFilePath = jerbo.JerboApp.class.getResource(
                        "/jerbo/resources/JerboArticlesCustom.properties")
                        .toString().substring(5);
            
            public void tableChanged(TableModelEvent e) {
                try {
                    customProperties.load(new FileInputStream(customPropertiesFilePath));
                    
                    TableSorter tableModel = (TableSorter) e.getSource();
                    for (int i = 0; i < tableModel.getColumnCount(); i++) {
                        customProperties.setProperty("table.columns[" + i + "].sortby.status",
                            String.valueOf(tableModel.getSortingStatus(i)));
                    }
                    
                    customProperties.store(new FileOutputStream(customPropertiesFilePath), null);
                    
                } catch (IOException ex) {
                    Logger.getLogger(JerboArticles.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    return;
                }
            }
            
        }
        
        articlesTable.getModel().addTableModelListener(new JTableSelectSortListener());
                
        TableColumnModel tcm = articlesTable.getColumnModel();
        tcm.addColumnModelListener(new TableChangeColumnSizeListener());
        
        tcm.getColumn(4).setCellRenderer(new jerbo.util.CurrencyTableCellRenderer());
        tcm.getColumn(5).setCellRenderer(new jerbo.util.VATTableCellRenderer());
        
        java.util.ResourceBundle customBundle = 
                java.util.ResourceBundle.getBundle("jerbo/resources/JerboArticlesCustom");
        
        for (int i = 0; i < tcm.getColumnCount(); i++) {
            tcm.getColumn(i).setPreferredWidth(Integer.parseInt(
                    customBundle.getString("table.columns["+i+"].width")));
            
            ((TableSorter) articlesTable.getModel())
                    .setSortingStatus(i, Integer.parseInt(
                    customBundle.getString("table.columns["+i+"].sortby.status")));
            
        }
        

        articlesTable.repaint();
    }
    
    private JerboArticlesManage manageBox;
}
